Stream field


In [1]:
from konfoo import Index, Byteorder, Stream

Item

Item type of the field class.


In [2]:
Stream.item_type


Out[2]:
ItemClass.Stream = 20

Checks if the field class is a bit field.


In [3]:
Stream.is_bit()


Out[3]:
False

Checks if the field class is a boolean field.


In [4]:
Stream.is_bool()


Out[4]:
False

Checks if the field class is a decimal number field.


In [5]:
Stream.is_decimal()


Out[5]:
False

Checks if the field class is a floating point number field.


In [6]:
Stream.is_float()


Out[6]:
False

Checks if the field class is a pointer field.


In [7]:
Stream.is_pointer()


Out[7]:
False

Checks if the field class is a stream field.


In [8]:
Stream.is_stream()


Out[8]:
True

Checks if the field class is a string field.


In [9]:
Stream.is_string()


Out[9]:
False

Field


In [10]:
stream = Stream(size=0)

In [11]:
stream = Stream()

Field view


In [12]:
stream


Out[12]:
Stream(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=0, bit_offset=0), bit_size=0, value='')

In [13]:
str(stream)


Out[13]:
'Stream(Index(byte=0, bit=0, address=0, base_address=0, update=False), Alignment(byte_size=0, bit_offset=0), 0, )'

In [14]:
repr(stream)


Out[14]:
"Stream(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=0, bit_offset=0), bit_size=0, value='')"

Field name


In [15]:
stream.name


Out[15]:
'Stream'

Field index


In [16]:
stream.index


Out[16]:
Index(byte=0, bit=0, address=0, base_address=0, update=False)

Byte index of the field within the byte stream.


In [17]:
stream.index.byte


Out[17]:
0

Bit offset relative to the byte index of the field within the byte stream.


In [18]:
stream.index.bit


Out[18]:
0

Absolute address of the field within the data source.


In [19]:
stream.index.address


Out[19]:
0

Base address of the byte stream within the data source.


In [20]:
stream.index.base_address


Out[20]:
0

Indexes the field and returns the index after the field.


In [21]:
stream.index_field(index=Index())


Out[21]:
Index(byte=0, bit=0, address=0, base_address=0, update=False)

Field alignment


In [22]:
stream.alignment


Out[22]:
Alignment(byte_size=0, bit_offset=0)

Byte size of the aligned field group.


In [23]:
stream.alignment.byte_size


Out[23]:
0

Bit offset of field in the aligned field group.


In [24]:
stream.alignment.bit_offset


Out[24]:
0

Field size


In [25]:
stream.bit_size


Out[25]:
0

Field length


In [26]:
len(stream)


Out[26]:
0

In [27]:
bool(stream)


Out[27]:
False

Field byte order


In [28]:
stream.byte_order


Out[28]:
Byteorder.auto = 'auto'

In [29]:
stream.byte_order.value


Out[29]:
'auto'

In [30]:
stream.byte_order.name


Out[30]:
'auto'

In [31]:
stream.byte_order = 'auto'

In [32]:
stream.byte_order = Byteorder.auto

Field value

Returns the stream field value as a lowercase hexadecimal encoded string.


In [33]:
stream.value


Out[33]:
''

Returns the stream field value as a number of bytes.


In [34]:
bytes(stream)


Out[34]:
b''

In [35]:
bytes(stream).hex()


Out[35]:
''

Returns the stream field value as a lowercase hexadecimal encoded string.


In [36]:
stream.hex()


Out[36]:
''

Field metadata

Returns the meatadata of the field as an ordered dictionary.


In [37]:
stream.describe()


Out[37]:
OrderedDict([('address', 0),
             ('alignment', [0, 0]),
             ('class', 'Stream'),
             ('index', [0, 0]),
             ('name', 'Stream'),
             ('order', 'auto'),
             ('size', 0),
             ('type', 'Field'),
             ('value', '')])

Field Resize

Resizing the stream field.


In [38]:
stream.resize(10)

View of the stream field.


In [39]:
stream


Out[39]:
Stream(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=10, bit_offset=0), bit_size=80, value='00000000000000000000')

Index of the stream field.


In [40]:
stream.index


Out[40]:
Index(byte=0, bit=0, address=0, base_address=0, update=False)

Name of the stream field.


In [41]:
stream.name


Out[41]:
'Stream10'

Alignment of the stream field.


In [42]:
stream.alignment


Out[42]:
Alignment(byte_size=10, bit_offset=0)

Bit size of the stream field.


In [43]:
stream.bit_size


Out[43]:
80

Byte length of the stream field.


In [44]:
len(stream)


Out[44]:
10

In [45]:
bool(stream)


Out[45]:
True

Value of the stream field


In [46]:
stream.value


Out[46]:
'00000000000000000000'

In [47]:
bytes(stream)


Out[47]:
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

In [48]:
bytes(stream).hex()


Out[48]:
'00000000000000000000'

In [49]:
stream.hex()


Out[49]:
'00000000000000000000'

Deserialize


In [50]:
stream.deserialize(bytes.fromhex('0102030405060708090a'))


Out[50]:
Index(byte=10, bit=0, address=10, base_address=0, update=False)

In [51]:
stream.value


Out[51]:
'0102030405060708090a'

In [52]:
bytes(stream)


Out[52]:
b'\x01\x02\x03\x04\x05\x06\x07\x08\t\n'

In [53]:
bytes(stream).hex()


Out[53]:
'0102030405060708090a'

In [54]:
stream.hex()


Out[54]:
'0102030405060708090a'

Serialize


In [55]:
buffer = bytearray()

In [56]:
stream.value = '0102030405060708090a'

In [57]:
stream.value = b'\x01\x02\x03\x04\x05\x06\x07\x08\t\n'

In [58]:
stream.serialize(buffer)


Out[58]:
Index(byte=10, bit=0, address=10, base_address=0, update=False)

In [59]:
buffer.hex()


Out[59]:
'0102030405060708090a'

In [60]:
bytes(stream).hex()


Out[60]:
'0102030405060708090a'

In [ ]: